package tools.httpdownloader.util;

import java.util.ArrayList;
import java.util.List;

public class HttpParser
{
	private final String CONTENT_START_TAG = "<a href=\"/\">Parent Directory</a>";
	private final String LINK_START = "<a href=";
	private final String LINK_END = "</a>";

	public List<String> getFileLinks(String parenturl, String htmlcontent)
	{
		List<String> links = new ArrayList<String>();
		StringBuilder sb = new StringBuilder(htmlcontent.substring(htmlcontent
				.indexOf(CONTENT_START_TAG)));
		htmlcontent = null;
		int index = 0;
		String link = "";

		while ((index = sb.indexOf(LINK_START)) > 0)
		{
			sb = sb.delete(0, index);
			sb = sb.delete(0, sb.indexOf(">"));
			link = sb.substring(0, sb.indexOf(LINK_END));
			sb = sb.delete(0, sb.indexOf(LINK_END));
			links.add(parenturl + "/" + link);
		}
		return links;
	}

}
